package controlador;

import accesoDatos.DAOReportes;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import java.io.*;

public class reporte7_2
{
    DAOReportes objDao = new DAOReportes();
    Object[][] res1;
    Object[][] res2;

    public void reporte7_2(String codigo, String nombre, String apellido) throws Exception
    {
        Document document=new Document();
        PdfWriter.getInstance(document,new FileOutputStream("reporte7_2.pdf"));
        document.open();
        PdfPTable table=new PdfPTable(3);
        PdfPCell cell = new PdfPCell (new Paragraph ("Documentos descargados por el Usuario "+nombre+" "+apellido+" con código "+codigo));
        cell.setBorderColor(BaseColor.WHITE);
        cell.setColspan (3);
        cell.setHorizontalAlignment (Element.ALIGN_CENTER);
        cell.setPadding (12.0f);
        table.addCell (cell);        
        cell = new PdfPCell (new Paragraph ("Nombre del Documento"));
        cell.setHorizontalAlignment (Element.ALIGN_CENTER);
        cell.setBorderColor(BaseColor.WHITE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setPadding (6.0f);
        table.addCell (cell);
        cell = new PdfPCell (new Paragraph ("Fecha de Descarga"));
        cell.setHorizontalAlignment (Element.ALIGN_CENTER);
        cell.setBorderColor(BaseColor.WHITE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setPadding (6.0f);
        table.addCell (cell);
        cell = new PdfPCell (new Paragraph ("Hora de Descarga"));
        cell.setHorizontalAlignment (Element.ALIGN_CENTER);
        cell.setBorderColor(BaseColor.WHITE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setPadding (6.0f);
        table.addCell (cell);

        res1 = objDao.getDatos7_2(codigo);
        res2 = objDao.getCount7_2(codigo);
        String res = res2[0][0].toString();
        int row = Integer.parseInt(res);
        int cont=0;

        for(int i=0;i<row;i++)
        {
            for(int j=0;j<3;j++)
            {
                String cel = res1[i][j].toString();
                cell = new PdfPCell(new Paragraph(cel));
                cell.setBorderColor(BaseColor.WHITE);
                if(cont%2==0)
                    cell.setBackgroundColor(BaseColor.GRAY);
                else
                    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
                table.addCell(cell);
            }
            cont++;
        }

        Image image = Image.getInstance ("imagen.jpg");
        document.add(image);
        document.add(table);
        document.close();
    }
}